<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<head>
</head>
<body>
	<div class="x-body">
		<form:form id="saveForm" modelAttribute="entity" cssStyle="margin-left: 20px;" cssClass="layui-form layui-form-pane">
			<div style="width:100%;height:400px;overflow: auto;">
				<input value="${entity.id}" type="hidden" name="id">

				<div class="layui-form-item">
					<div class="layui-inline">
						<label for="name" class="layui-form-label"><span class="x-red">*</span>昵称</label>
						<div class="layui-input-inline">
							<form:input path="name" cssClass="required layui-input" maxlength="50"></form:input>
						</div>
					</div>
					<div class="layui-inline">
						<label for="code" class="layui-form-label">code</label>
						<div class="layui-input-inline">
							<form:input path="code" cssClass=" layui-input" maxlength="50" disabled="true" placeholder="自动生成：权限令牌"></form:input>
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<label for="resourceValue" class="layui-form-label"><span class="x-red">*</span>资源</label>
					<div class="layui-input-block">
						<input type="text" id="resourceInput" class="input-text layui-input" value=""  onclick="showMenu('resourceInput',false);" readonly="readonly" >
						<input type="hidden" id="resourceValue" value=""  name="resIds" >
						<div  id="menuContent_resourceInput" class="ztree" style="position: absolute;display: none;padding: 0px;z-index:999;" >
							<ul id="showResourceTree"  class="ztree"  style="margin-top: 0px; width: 180px; height: 150px; -moz-user-select: none;"></ul>
						</div>
					</div>
				</div>

				<div class="layui-form-item layui-form-text">
					<label for="remark" class="layui-form-label"><span class="x-red">*</span>备注</label>
					<div class="layui-input-block">
						<textarea name="remark" id="remark"  placeholder="请输入内容" class="layui-textarea">${entity.remark}</textarea>
					</div>
				</div>

				<div style="height: 60px"></div>
			</div>
			<c:if test="${!detail}">
				<div style="width: 100%;height: 55px;background-color: white;border-top:1px solid #e6e6e6;
		  position: fixed;bottom: 1px;margin-left:-20px;">
					<div class="layui-form-item" style=" float: right;margin-right: 30px;margin-top: 8px">
						<a  class="layui-btn layui-btn-normal" lay-filter="add" lay-submit>确定</a>
						<a  class="layui-btn layui-btn-primary" id="close">取消</a>
					</div>
				</div>
			</c:if>
		</form:form>
	</div>
</body>
<myfooter>
	<script type="text/javascript">
        $(document).ready(function() {
            var detail='${detail}';
            if(detail=="true"){
                $("form").disable();
            }
        });
        $('#close').click(function(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });

      var validate = $("#saveForm").validate();
        var setting={
            check: {
                enable: true,
                chkStyle : "checkbox",
                chkboxType: { "Y": "ps", "N": "s" }
            },
            callback: {
                onCheck: zTreeOnCheck
            }
        };
        var roleId = "${entity.id}";
        $.ajax({
            type: 'POST',
            dataType : "json",
            url: "${ctx}/role/getResourceListDateForRole?roleId="+roleId,
            success:function(data){
                $.fn.zTree.init($("#showResourceTree"), setting,data);
                $("#resourceInput").attr("value", getTreeCheckboxNameCheck("showResourceTree"));
                $("#resourceValue").attr("value",getTreeCheckboxIdCheck("showResourceTree"));
            }
        });
        function  zTreeOnCheck(event, treeId, treeNode) {
            $("#resourceInput").attr("value", getTreeCheckboxNameCheck("showResourceTree"));
            $("#resourceValue").attr("value",getTreeCheckboxIdCheck("showResourceTree"));
        };


        layui.use(['form','layer','upload'], function(){
            $ = layui.jquery;
            var form = layui.form,
				layer = layui.layer;

            //监听提交
            form.on('submit(add)', function(data){
				if(validate.form()){
                    var indexFormSubmit = layer.load(2, {shade: [0.3, '#333']});
                    $.ajax({
                        url:'${ctx}/role/saveEntity',
                        type:'post',
                        data:data.field,
                        async:false,
                        traditional: true,
                        success:function(d){
                            layer.close(indexFormSubmit);
                            if(d.flag=="200"){
                                parent.$("#refresh").trigger("click");
                                window.parent.layui.table.reload('pageList');
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.top.layer.msg(d.msg,{icon:6,offset: 'rb',area:['120px','80px'],anim:2});
                            }else{
                                window.top.layer.msg(d.msg,{icon:5,offset: 'rb',area:['120px','80px'],anim:2});
                            }
                        },error:function(){
                            layer.close(indexFormSubmit);
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            window.top.layer.msg('请求失败',{icon:5,offset: 'rb',area:['120px','80px'],anim:2});
                        }
                    })
				}
                return false;
            });
            form.render();
        });
	</script>
</myfooter>